package com.assisjrs.jpaandroid.persistence.converter;

import java.lang.reflect.Field;

import android.database.Cursor;

import com.assisjrs.jpaandroid.persistence.ConverterDatabase;
import com.assisjrs.jpaandroid.persistence.Entity;

public class IntegerConverter implements ConverterDatabase<Integer, Integer> {
	@Override
	public Integer getFromInstance(final Field field, final Entity entity) {
		try {
			return (Integer) field.get(entity);
		} catch (final IllegalArgumentException e) {
			throw new RuntimeException(e);
		} catch (final IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public Integer getToInstance(final Cursor cursor, final int columnIndex, final Class<?> type) {
		return cursor.getInt(columnIndex);
	}
}
